<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分布式事务解决方案深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* 首字下沉效果 */
        .drop-cap::first-letter {
            float: left;
            font-size: 4.5rem;
            line-height: 3.5rem;
            padding-right: 0.5rem;
            margin-top: 0.25rem;
            font-weight: 700;
            color: #4338ca;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 代码块美化 */
        .code-block {
            background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
            border-radius: 12px;
            padding: 1.5rem;
            margin: 1.5rem 0;
            position: relative;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        }
        
        .code-block::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: linear-gradient(90deg, #6366f1, #8b5cf6, #ec4899);
        }
        
        .code-block pre {
            color: #e2e8f0;
            font-family: 'Fira Code', monospace;
            font-size: 0.875rem;
            line-height: 1.5;
            overflow-x: auto;
            margin: 0;
        }
        
        /* 卡片悬停效果 */
        .feature-card {
            transition: all 0.3s ease;
            background: white;
            border-radius: 16px;
            padding: 2rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
        }
        
        /* 标题装饰 */
        .section-title {
            position: relative;
            padding-left: 1.5rem;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(180deg, #6366f1, #8b5cf6);
            border-radius: 2px;
        }
        
        /* 表格美化 */
        .comparison-table {
            background: white;
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .comparison-table th {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
            color: white;
            font-weight: 600;
            padding: 1rem;
            text-align: left;
        }
        
        .comparison-table td {
            padding: 1rem;
            border-bottom: 1px solid #e5e7eb;
        }
        
        .comparison-table tr:hover {
            background-color: #f9fafb;
        }
        
        /* 动画效果 */
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        /* 引用样式 */
        .quote-box {
            background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
            border-left: 4px solid #f59e0b;
            padding: 1.5rem;
            margin: 2rem 0;
            border-radius: 8px;
            position: relative;
        }
        
        .quote-box::before {
            content: '\f10d';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            top: -10px;
            left: 20px;
            font-size: 2rem;
            color: #f59e0b;
            opacity: 0.3;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-gradient-to-br from-indigo-600 via-purple-600 to-pink-500 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    分布式事务解决方案
                    <span class="block text-3xl md:text-4xl mt-2 text-indigo-200">深度解析与实战指南</span>
                </h1>
                <p class="text-xl md:text-2xl text-indigo-100 mb-8 leading-relaxed">
                    探索微服务架构下的数据一致性保障机制
                </p>
                <div class="flex justify-center space-x-6 text-sm">
                    <div class="flex items-center">
                        <i class="fas fa-clock mr-2"></i>
                        <span>阅读时间：15分钟</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-layer-group mr-2"></i>
                        <span>技术深度：高级</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 110C120 100 240 80 360 70C480 60 600 60 720 65C840 70 960 80 1080 85C1200 90 1320 90 1380 90L1440 90V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0V120Z" fill="white"/>
            </svg>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction -->
        <section class="mb-16 animate-fadeInUp">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                    在当今微服务架构盛行的时代，分布式系统的应用越来越广泛。随着系统复杂度的提升，分布式事务的处理成为了一个关键且棘手的问题。分布式事务需要保证在分布式环境下，多个操作要么全部成功提交，要么全部回滚，以此确保数据的一致性。
                </p>
            </div>
        </section>

        <!-- Visual Diagram -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-indigo-50 to-purple-50 rounded-2xl p-8">
                <h3 class="text-2xl font-bold text-gray-800 mb-6 text-center">
                    <i class="fas fa-project-diagram mr-3 text-indigo-600"></i>
                    分布式事务架构概览
                </h3>
                <div class="mermaid">
                    graph TB
                        subgraph "微服务架构"
                            A[客户端请求] --> B[API网关]
                            B --> C[订单服务]
                            B --> D[库存服务]
                            B --> E[支付服务]
                            
                            C --> F[(订单数据库)]
                            D --> G[(库存数据库)]
                            E --> H[(支付数据库)]
                        end
                        
                        subgraph "分布式事务协调"
                            I[事务协调器]
                            I -.->|2PC| C
                            I -.->|TCC| D
                            I -.->|Saga| E
                        end
                        
                        style A fill:#fef3c7,stroke:#f59e0b,stroke-width:2px
                        style I fill:#ddd6fe,stroke:#8b5cf6,stroke-width:2px
                </div>
            </div>
        </section>

        <!-- Basic Concepts -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 section-title">
                <i class="fas fa-book-open mr-3 text-purple-600"></i>
                一、分布式事务基础概念
            </h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="feature-card">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-server text-indigo-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">分布式环境特点</h3>
                    </div>
                    <p class="text-gray-600 leading-relaxed">
                        与传统单机事务不同，分布式事务涉及多个独立的服务节点或数据库。这些服务可能部署在不同的服务器上，使用不同的技术栈和数据存储方案。
                    </p>
                </div>
                <div class="feature-card">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-shopping-cart text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">典型应用场景</h3>
                    </div>
                    <p class="text-gray-600 leading-relaxed">
                        电商系统的下单流程是分布式事务的典型场景：创建订单、扣减库存、处理支付等操作分布在不同服务中，需要保证整体的原子性和一致性。
                    </p>
                </div>
            </div>
        </section>

        <!-- 2PC Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 section-title">
                <i class="fas fa-sync-alt mr-3 text-indigo-600"></i>
                二、两阶段提交（2PC）
            </h2>
            
            <div class="bg-white rounded-2xl shadow-lg p-8 mb-8">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">（一）2PC 原理</h3>
                <div class="grid md:grid-cols-2 gap-8">
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 w-10 h-10 bg-indigo-100 rounded-full flex items-center justify-center mr-4 mt-1">
                                <span class="text-indigo-600 font-bold">1</span>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800 mb-2">准备阶段（Prepare Phase）</h4>
                                <p class="text-gray-600">协调者向所有参与者发送事务预提交请求，参与者执行事务但不提交，将结果反馈给协调者。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-4 mt-1">
                                <span class="text-purple-600 font-bold">2</span>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800 mb-2">提交阶段（Commit Phase）</h4>
                                <p class="text-gray-600">根据准备阶段的结果，协调者决定是提交还是回滚事务，并通知所有参与者执行相应操作。</p>
                            </div>
                        </div>
                    </div>
                    <div class="bg-gray-50 rounded-lg p-6">
                        <div class="mermaid">
                            sequenceDiagram
                                participant C as 协调者
                                participant A as 参与者A
                                participant B as 参与者B
                                
                                C->>A: 准备请求
                                C->>B: 准备请求
                                A-->>C: 准备就绪